<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ page import="java.io.*,java.util.*,java.sql.*"%>
<%@ page import="com.techbirds.ms.model.UserDto"%>
<%@ page import="org.apache.ibatis.io.Resources"%>
<%@ page import="org.apache.ibatis.session.SqlSession"%>
<%@ page import="org.apache.ibatis.session.SqlSessionFactory"%>
<%@ page import="org.apache.ibatis.session.SqlSessionFactoryBuilder"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%!private static SqlSessionFactory sqlSessionFactory;%>
	<%!private static Reader reader;%>

	<%
		out.println("Hello World<br/>");//环境测试,
		//mybatis定义配置文件位置
		String resource = "conf.xml";
		//使用MyBatis提供的Resources类加载mybatis的配置文件（它也加载关联的映射文件）
		reader = Resources.getResourceAsReader("conf.xml");
		//构建sqlSession的工厂
        sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader);
		//创建能执行映射文件中sql的sqlSession
		SqlSession session2 = sqlSessionFactory.openSession();
		//conf.xml里把mybatis的map文件指向UserDtoMapper.xml
		/**
		 * 映射sql的标识字符串，
		 * com.techbirds.ms.dao.UserDtoMapper是UserDtoMapper.xml文件中mapper标签的namespace属性的值，
		 * selectByPrimaryKey是select标签的id属性值，通过select标签的id属性值就可以找到要执行的SQL
		 */
		String statement = "com.techbirds.ms.dao.UserDtoMapper.selectByPrimaryKey";//映射sql的标识字符串
		//执行查询返回一个唯一user对象的sql
		UserDto user = session2.selectOne(statement, 3);
		out.println("<br/>test库user表，第3条记录:" + user.getName());
	%>
</body>
</html>